package com.stoken.web.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.stoken.domain.TravelLineType;
import com.stoken.service.TravelLineTypeService;
import com.symbio.commons.Compositor;
import com.symbio.commons.Compositor.CompositorType;
import com.symbio.commons.Page;
import com.symbio.utils.WebUtils;

@Controller
@RequestMapping("/travelLType")
public class TravelLineTypeControl {
	
	@Autowired
	private TravelLineTypeService travelLineTypeService;
	
	
	/**
	 * 旅游类型列表
	 * @return
	 */
	@RequestMapping("/backstage/loadTypeList")
	public String loadNoticeList(){		
		return "/backstage/travel/travelTypeList";
	}
	
	/**
	 * 增加旅游类型
	 */
	@RequestMapping(value="/backstage/travelTypeAdd",method=RequestMethod.POST)
	public String addTravelType(TravelLineType travelLineType,HttpServletRequest request,ModelMap modeMape){	
		
		
		travelLineTypeService.save(travelLineType);			
		
		return "/backstage/travel/travelTypeList";
	}
	
	/**
	 * 查询旅游类型数据
	 * @param request
	 * @param modeMape
	 * @return
	 */
	@RequestMapping("/backstage/travelTypeData")
	public String travelTypeData(HttpServletRequest request,ModelMap modeMape)
	{
	
		Page<TravelLineType> pageData = new Page<TravelLineType>();
		//给pageData设置参数
		WebUtils.setPageDataParameter(request, pageData);
		Compositor compositor = new Compositor("id",CompositorType.DESC);
		pageData.setCompositor(compositor);
		
		
		pageData = travelLineTypeService.find(pageData);		
	    modeMape.addAttribute("pageData", pageData);
	    
	    Pagination page = new Pagination();
		page.setIntTotalNum((int)pageData.getPagination().getTotalCount());
		page.setCurpage(pageData.getPagination().getPageNo());
		page.setPagenum(pageData.getPagination().getPageSize());
		modeMape.addAttribute("pagination", page.showPages());
	    
		return "/backstage/travel/travelTypeData";
	}
	
	/**
	 * 删除旅游类型
	 * @param request
	 * @param modeMape
	 * @param id
	 * @return
	 */
	@RequestMapping("/backstage/deleteTravelType")
	public String deleteType(HttpServletRequest request,ModelMap modeMape,Long travelTypeId){		
		travelLineTypeService.delete(travelTypeId);
		return "/backstage/travel/travelTypeList";
	}
	
	
	/**
	 * 加载新增旅游类型
	 * @return
	 */
	@RequestMapping("/backstage/loadTravelTypeAddPage")
	public String loadAddTravelTypePage(){
		return "/backstage/travel/addTravelType";
		
	}
	
}
